//
//  ProductCard.swift
//  shop
//
//  Created by chen on 2025/5/13.
//

import SwiftUI
import Kingfisher

struct ProductCard: View {
    
    var item: GoodsItem
    
    @State private var showFlag: Bool = true
    
    var body: some View {
        VStack(alignment: .leading, spacing: 0) {
            HStack(spacing: 0){
                KFImage.url(URL(string: item.mainPic))
                       .loadDiskFileSynchronously()
                       .cacheMemoryOnly()
                       .fade(duration: 0.35)
                       .resizable()
                       .aspectRatio(contentMode: .fill)
            }
            
            VStack(alignment: .leading, spacing: 10){
                Text("\(item.dtitle)")
                    .font(.system(size: 15))
                    .foregroundStyle(.black)
                
                HStack(alignment: .lastTextBaseline ,spacing: 2) {
                    Text("券后")
                        .font(.system(size: 15))
                        .foregroundStyle(.red)
                    
                    Text("¥")
                        .font(.system(size: 15))
                        .foregroundStyle(.red)
                    
                    Text("\(item.actualPrice.formatMoney())")
                        .font(.system(size: 20))
                        .foregroundStyle(.red)
                        .bold()
                        .lineLimit(1)
                        .minimumScaleFactor(0.5)
                    
                    Spacer()
                    
                    HStack(spacing: 2) {
                        Text("¥")
                            .strikethrough()
                        Text("\(item.originalPrice.formatMoney())")
                            .lineLimit(1)
                            .minimumScaleFactor(0.5)
                            .strikethrough()
                    }
                    .font(.system(size: 16))
                    .foregroundStyle(.gray)
                }
                
                Text("销量：\(item.monthSales)")
                    .font(.system(size: 12))
                    .foregroundStyle(.black.opacity(0.65))
            }
            .padding(10)
        }
        .frame(maxWidth: .infinity)
        .background(.white)
        .cornerRadius(8)
        .shadow(color: Color.gray.opacity(0.2), radius: 4, x: 0, y: 2)
    }
}

#Preview {
    ZStack{
        Color.gray
            .opacity(0.23)
            .ignoresSafeArea()
        
        ProductCard(item: GoodsItem())
    }
}
